const mongoose = require("../config/db");
const moment = require('moment')
const UserSchema = mongoose.Schema({
  username: {
    type: String,
    required: true,
    unique: true,
    minlength: 2,
    maxlength: 20
  },
  password: {
    type: String,
    required: true,
    minlength: 6,
    maxlength: 18
  },
  sex: {
    type: Number,
    default: 0,
    required: true
  },
  tel: {
    type: String,
    required: true
  },
  class_grade: {
    type: String,
    required: true
  },
  organization: {
    type: String,
    required: true
  },
  // admin 超级管理员
  // normal 普通用户
  role: {
    type: String,
    required: true
  },
  state: {
    type: Number,
    default: 1,
    required: true
  },
  add_time: {
    type: Date,
    default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  }
}, {
  versionKey: false
})
const UsersModel = mongoose.model("Users", UserSchema, "users");
// UsersModel.create({
//   "student_num": 1,
//   "username": "ecddcscc",
//   "password": "123456",
//   "sex": 2,
//   "tel": "13777773456",
//   "class_grade": "二班",
//   "organization": "羽毛球社",
//   "role": "管理员",
//   "add_time": new Date()
// });
module.exports = UsersModel;